package com.example.springboot01.config;

import com.example.springboot01.execs.CustomException;
import com.example.springboot01.resp.enums.CommonRespEnum;

public class TeacherContextHolder {

    private static ThreadLocal<Integer>  holder = new ThreadLocal<>();

    public static void set(Integer teacherId){
        holder.set(teacherId);
    }

    public static Integer get(){
        final Integer integer = holder.get();
        if (integer == null) {
            throw new CustomException(CommonRespEnum.UNAUTHORIZED);
        }
        return integer;
    }

    public static void remove(){
        holder.remove();
    }
}
